using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using RideMe.Presentation.Properties;
using RideMe.Core;

namespace RideMe.Presentation
{
    public partial class NewProjectDialog : DialogBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="T:NewProjectDialog"/> class.
        /// </summary>
        public NewProjectDialog()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Gets the project location.
        /// </summary>
        /// <value>The project location.</value>
        public string ProjectLocation       
        {
            get 
            { 
                return this.GetProjectLocation(); 
            }
        }

        /// <summary>
        /// Retrieves the project location from the two textboxes.
        /// </summary>
        /// <returns></returns>
        private string GetProjectLocation()
        {
            return Path.Combine(locationTextBox.Text, projectNameTextBox.Text);
        }

        /// <summary>
        /// Previews the path.
        /// </summary>
        private void UpdatePathPreview()
        {
            this.previewLabel.Text = Resources.PathToProject + this.GetProjectLocation();
        }

        /// <summary>
        /// Handles the Click event of the browseButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void browseButton_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Options.Instance.LastProjectCreationLocation))
            {
                folderBrowserDialog.SelectedPath = Options.Instance.LastProjectCreationLocation;
            }
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                locationTextBox.Text = folderBrowserDialog.SelectedPath;
            }
        }

        /// <summary>
        /// Handles the Click event of the okButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void okButton_Click(object sender, EventArgs e)
        {
            if (locationTextBox.Text.Trim().Length != 0)
            {
                Options.Instance.LastProjectCreationLocation = locationTextBox.Text;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        /// <summary>
        /// Handles the TextChanged event of the projectNameTextBox control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void projectNameTextBox_TextChanged(object sender, EventArgs e)
        {
            this.UpdatePathPreview();
        }

        /// <summary>
        /// Handles the TextChanged event of the locationTextBox control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void locationTextBox_TextChanged(object sender, EventArgs e)
        {
            this.UpdatePathPreview();
        }

    }
}

